package com.itheima.controller;

import com.itheima.pojo.Dept;
import com.itheima.pojo.Result;
import com.itheima.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Mapper;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.logging.Logger;

@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {
//    private static Logger log= (Logger) LoggerFactory.getLogger(DeptController.class);
//    @RequestMapping(value = "/depts",method = RequestMethod.GET)

    @Autowired
    private DeptService deptService;

    @GetMapping
    public Result list() {
        log.info("查询所有数据");
        List<Dept> list = deptService.list();
        return Result.success(list);
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("本次删除id为：{}",id);
        deptService.delete(id);
        return Result.success();
    }
    @PostMapping
    public Result add(@RequestBody Dept dept){
        log.info("插入成功！");
        deptService.insert(dept);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result select(@PathVariable Integer id){
        log.info("查询id为：{}",id);
        Dept dept=deptService.select(id);
        return Result.success(dept);
    }
    @PutMapping
    public Result update(@RequestBody Dept dept){
        log.info("修改的部门为：{}",dept);
        deptService.update(dept);
        return Result.success();
    }
}
